﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeWork3_2
{
    //声明一个委托类型,定义事件处理函数的格式
    public delegate void TickHandler(object sender,EventArgs args);
    public delegate void AlarmHandler(object sender,EventArgs args);
    public class EventArgs//这些事件
    {
       public string time { get; set; }
    }
    public class Clock
    {
        //定义事件,相当于创建一个委托实例
        public event TickHandler OnTick;
        public event AlarmHandler OnAlarm;
        public void Tick(string time1)
        {
            Console.Write("调用Tick委托：");
            OnTick(this, new EventArgs() { time=time1});
        }
        public void Alarm(string time1)
        {
            Console.Write("调用Alarm委托：");
            OnAlarm(this, new EventArgs() { time = time1 });
        }
    }
    public class Form
    {
        public Clock clock = new Clock();
        public Form()
        {
            clock.OnTick += clock_tick;
            //TickHandler t=(sender, args)=>{ Console.WriteLine(233); };
            //clock.OnTick += t;
            clock.OnAlarm += clock_alarm;
        }
        void clock_tick(object sender, EventArgs args)
        {
            Console.WriteLine($"闹钟在{args.time}时刻滴答了");
        }
        void clock_alarm(object sender, EventArgs args)
        {
            Console.WriteLine($"闹钟在{args.time}时刻响铃了");
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            Form form1=new Form();
            form1.clock.Tick("16:50");
            form1.clock.Alarm("16:53");
            Console.ReadKey();
        }
    }
}
